import React from 'react';
import "./index.css";
import { Icon } from 'antd';
import UserServer from "../../Server/User";
import UserCheck from "../../utils/UserCheck";
import CommonUtil from "../../utils/Common";

export default class Authentication extends React.Component{
    constructor(props){
        super();
        this.state={
            changeTab:props.changeTab,
            isDrone:true,
            droneBackground:"linear-gradient(265deg,rgba(38,210,255,1) ,rgba(35,126,246,1))",
            caBackground:"",

            realName:"", //姓名
            id:"", //身份证
            authSuccess:"",
            authing:""
        };
        //判断用户是否认证
        UserServer.SelectAuthenticationInformation(UserCheck.GetUserID())
        .then(response=>{
            //redirect
            //已经认证过,跳转
            // console.log("success")
            this.setState({
                realName:response.data[0].realName,
                id:CommonUtil.EncryptionID(response.data[0].realDocumentNumber),
            });
            switch(response.data[0].realStatus){
                case "0":
                    this.setState({
                        authing:(
                            <div className="Top_Recovering">
                                <div className="Top_Certified_Icon_T"><Icon type="enter"  style={{ fontSize: '10px', color: '#FE5710',margin:' 0px 1px 4px' }}/></div>
                                <div className="Top_Certified_Word_T">认证中</div>
                            </div>
                        )
                    })
                    break;
                case "1":
                    break;
                case "2":
                    this.setState({
                        authSuccess:(<div className="Top_Certified">
                        <div className="Top_Certified_Icon"><Icon type="check" style={{ fontSize: '', color: '#FEBF10' }}/></div>
                        <div className="Top_Certified_Word">已认证</div>
                    </div>)
                    })
                    break;
                default:
                    break;
            }
            //0:审核中
            //1:审核失败
            //2：审核成功
            // console.log(response);

            // console.log(response.data.realId);
            // console.log(response.data.realName);
            // console.log(response.data.realDocumentNumber);
        },reject=>{
            // console.log("reject")
            // console.log(reject)
            // this.SetErr(reject.msg);
        })
    }
    Add(e){
        let frame=window.parent.document.getElementById("Layout_MainContainer");
        if(this.state.isDrone){
            frame.src="/productInfo";
        }
        else{
            frame.src="/certificate_type";
        }
    }
    ChaneDrone(){
        this.state.changeTab(true);
        this.setState({
            isDrone:true,
            droneBackground:"linear-gradient(265deg,rgba(38,210,255,1) ,rgba(35,126,246,1))",
            caBackground:""
        });
    }
    ChangeCA(){
        this.state.changeTab(false);
        this.setState({
            isDrone:false,
            caBackground:"linear-gradient(265deg,rgba(38,210,255,1) ,rgba(35,126,246,1))",
            droneBackground:""
        });
    }
    render()
    {
        return(
            <div className="Authentication_Top">
                <div className="Authentication_Top_Top">
                    <div className="Top_Name">{this.state.realName}</div>
                    {this.state.authSuccess}
                    {this.state.authing}
                    <div className="Top_Add" onClick={e=>this.Add(e)}>
                        <div>+</div><span>添加认证</span>
                    </div>
                </div>
                <div className="Authentication_Top_Middle">
                {this.state.id}
                </div>
                <div className="Authentication_Top_Bottom">
                    <div  style={{background:this.state.droneBackground}} onClick={e=>this.ChaneDrone(e)} className="Authentication_Top_Bottom_T">飞行器认证(0)</div>
                    <div style={{background:this.state.caBackground}} onClick={e=>this.ChangeCA(e)} className="Authentication_Top_Bottom_B">飞行执照认证(0)</div>
                </div>
            </div>
        );
    }
}